include(gbversion.cmake)
project(gpsbabel LANGUAGES C CXX VERSION ${GB.VERSION})
-set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# Do this after we set up common variables but before creating other
#ifndef DEFS_H_INCLUDED_
#define DEFS_H_INCLUDED_
-#include <cmath> // for M_PI
#include <cstddef> // for NULL, nullptr_t, size_t
#include <cstdint> // for int32_t, uint32_t
#include <cstdio> // for NULL, fprintf, FILE, stdout
#include <QString> // for QString
#include <QStringView> // for QStringView
#include <QTextCodec> // for QTextCodec
-#include <QVector> // for QVector
#include <Qt> // for CaseInsensitive
#include <QtGlobal> // for QForeachContainer, qMakeForeachContainer, foreach, qint64
#define CSTR(qstr) ((qstr).toUtf8().constData())
#define CSTRc(qstr) ((qstr).toLatin1().constData())
-/*
- * Amazingly, this constant is not specified in the standard...
- */
-#ifndef M_PI
-# define M_PI 3.14159265358979323846
-#endif
/*
* The constants marked "exact in decimal notation" may be more accurately
class wp_flags
{
public:
- wp_flags() :
- shortname_is_synthetic(0),
- fmt_use(0),
- is_split(0),
- new_trkseg(0),
- marked_for_deletion(0) {}
- unsigned int shortname_is_synthetic:1;
- unsigned int fmt_use:2; /* lightweight "extra data" */
- unsigned int is_split:1; /* the waypoint represents a split */
- unsigned int new_trkseg:1; /* True if first in new trkseg. */
- unsigned int marked_for_deletion:1; /* True if schedulded for deletion. */
+ unsigned int shortname_is_synthetic:1{0};
+ unsigned int fmt_use:2{0}; /* lightweight "extra data" */
+ unsigned int is_split:1{0}; /* the waypoint represents a split */
+ unsigned int new_trkseg:1{0}; /* True if first in new trkseg. */
+ unsigned int marked_for_deletion:1{0}; /* True if schedulded for deletion. */
};
/*
class op_flags
{
public:
- op_flags() :
- temperature(false),
- proximity(false),
- course(false),
- speed(false),
- geoidheight(false),
- depth(false) {}
- bool temperature:1; /* temperature field is set */
- bool proximity:1; /* proximity field is set */
- bool course:1; /* course field is set */
- bool speed:1; /* speed field is set */
- bool geoidheight:1; /* geoidheight field is set */
- bool depth:1; /* depth field is set */
+ bool temperature:1{false}; /* temperature field is set */
+ bool proximity:1{false}; /* proximity field is set */
+ bool course:1{false}; /* course field is set */
+ bool speed:1{false}; /* speed field is set */
+ bool geoidheight:1{false}; /* geoidheight field is set */
+ bool depth:1{false}; /* depth field is set */
/* !ToDo!
- unsigned int altitude:1; /+ altitude field is set +/
+ unsigned int altitude:1{false}; /+ altitude field is set +/
... and hdop,pdop,vdop,fix,sat,heartrate,cadence,power,
odometer_distance
*/
for (int i = 0; i < n; i++) {
GPS_Way_Del(&tx_routelist[i]);
}
-
+
xfree(tx_routelist);
}
struct garmin_fs_flags_t {
public:
- garmin_fs_flags_t() :
- icon(0),
- wpt_class(0),
- display(0),
- category(0),
- city(0),
- state(0),
- facility(0),
- cc(0),
- cross_road(0),
- addr(0),
- country(0),
- phone_nr(0),
- phone_nr2(0),
- fax_nr(0),
- postal_code(0),
- email(0),
- duration(0)
-#ifdef GMSD_EXPERIMENTAL
- , subclass(0)
-#endif
- {}
-
- unsigned int icon:1;
- unsigned int wpt_class:1;
- unsigned int display:1;
- unsigned int category:1;
- unsigned int city:1;
- unsigned int state:1;
- unsigned int facility:1;
- unsigned int cc:1;
- unsigned int cross_road:1;
- unsigned int addr:1;
- unsigned int country:1;
- unsigned int phone_nr:1;
- unsigned int phone_nr2:1;
- unsigned int fax_nr:1;
- unsigned int postal_code:1;
- unsigned int email:1;
- unsigned int duration:1;
+
+ unsigned int icon:1{0};
+ unsigned int wpt_class:1{0};
+ unsigned int display:1{0};
+ unsigned int category:1{0};
+ unsigned int city:1{0};
+ unsigned int state:1{0};
+ unsigned int facility:1{0};
+ unsigned int cc:1{0};
+ unsigned int cross_road:1{0};
+ unsigned int addr:1{0};
+ unsigned int country:1{0};
+ unsigned int phone_nr:1{0};
+ unsigned int phone_nr2:1{0};
+ unsigned int fax_nr:1{0};
+ unsigned int postal_code:1{0};
+ unsigned int email:1{0};
+ unsigned int duration:1{0};
#ifdef GMSD_EXPERIMENTAL
- unsigned int subclass:1;
+ unsigned int subclass:1{0};
#endif
};
QString utf_string;
};
- /* Special Member Functions */
-
- Geocache() :
- id(0),
- type(type_t::gt_unknown),
- container(container_t::gc_unknown),
- diff(0),
- terr(0),
- is_archived(status_t::gs_unknown),
- is_available(status_t::gs_unknown),
- is_memberonly(status_t::gs_unknown),
- has_customcoords(status_t::gs_unknown),
- placer_id(0),
- favorite_points(0)
- {}
-
/* Member Functions */
void set_type(const QString& type_name);
/* Data Members */
- long long id; /* The decimal cache number */
- type_t type:5;
- container_t container:4;
- unsigned int diff:6; /* (multiplied by ten internally) */
- unsigned int terr:6; /* (likewise) */
- status_t is_archived:2;
- status_t is_available:2;
- status_t is_memberonly:2;
- status_t has_customcoords:2;
+ long long id{0}; /* The decimal cache number */
+ type_t type:5{type_t::gt_unknown};
+ container_t container:4{container_t::gc_unknown};
+ unsigned int diff:6{0}; /* (multiplied by ten internally) */
+ unsigned int terr:6{0}; /* (likewise) */
+ status_t is_archived:2{status_t::gs_unknown};
+ status_t is_available:2{status_t::gs_unknown};
+ status_t is_memberonly:2{status_t::gs_unknown};
+ status_t has_customcoords:2{status_t::gs_unknown};
gpsbabel::DateTime last_found;
QString placer; /* Placer name */
- int placer_id; /* Placer id */
+ int placer_id{0}; /* Placer id */
QString hint; /* all these UTF8, XML entities removed, May be not HTML. */
UtfString desc_short;
UtfString desc_long;
- int favorite_points;
+ int favorite_points{0};
QString personal_note;
private:
};
/* Member Functions */
-
+
static void takeout_fatal(const QString& message);
static void takeout_warning(const QString& message);
static Waypoint* takeout_waypoint(int lat_e7, int lon_e7, const QString* shortname, const QString* description, const QString* start_str);
#include <cerrno>
#include <cmath>
#include <cstdio>
+#include <numbers>
#include <tuple>
static constexpr double EARTH_RAD = 6378137.0;
}
} else {
/* lp is 0 when 3 is 90 degrees from the great circle */
- return M_PI / 2;
+ return std::numbers::pi / 2;
}
} else {
/* la is 0 when 1 and 2 are either the same point or 180 degrees apart */
#ifndef GRTCIRC_H
#define GRTCIRC_H
+#include <numbers> // for inv_pi
+
double gcdist(double lat1, double lon1, double lat2, double lon2);
double heading(double lat1, double lon1, double lat2, double lon2);
double heading_true_degrees(double lat1, double lon1, double lat2, double lon2);
double* reslat, double* reslon);
/* Degrees to radians */
-constexpr double kDegreesPerRadian = 180.0 / M_PI;
+constexpr double kDegreesPerRadian = 180.0 * std::numbers::inv_pi;
constexpr double DEG(double x) { return x * kDegreesPerRadian; }
/* Radians to degrees */
#include <Qt> // for CaseInsensitive
#include <QtGlobal> // for qRound
-#include <cmath> // for atan, tan, M_PI, log, sinh
+#include <cmath> // for atan, tan, log, sinh
#include <cstdio> // for snprintf, SEEK_SET
#include <cstring> // for strncpy, memcpy, memset
+#include <numbers> // for inv_pi, pi
#include "defs.h" // for Waypoint, be_read32, be_read16, be_write32, fatal, xfree, be_write16, route_head, xcalloc, track_add_wpt, xstrndup
#include "mkshort.h" // for MakeShort
#define WPT_MAGIC2 0x02030024L // New for 2013. No visible diff?!
#define RTE_MAGIC 0x03030088L
-#define EAST_SCALE 20038297.0 /* this is i1924_equ_axis*M_PI */
+#define EAST_SCALE 20038297.0 /* this is i1924_equ_axis*pi */
#define i1924_equ_axis 6378388.0
#define i1924_polar_axis 6356911.946
{
constexpr double cos_ae = 0.9966349016452;
constexpr double cos2_ae = cos_ae * cos_ae;
- const double gdr = gd_lat *M_PI / 180.0;
+ const double gdr = gd_lat * std::numbers::pi / 180.0;
- return atan(cos2_ae * tan(gdr)) * 180.0/M_PI;
+ return atan(cos2_ae * tan(gdr)) * 180.0 * std::numbers::inv_pi;
}
/* Takes a latitude in degrees,
{
constexpr double cos_ae = 0.9966349016452;
constexpr double cos2_ae = cos_ae * cos_ae;
- const double gcr = gc_lat *M_PI / 180.0;
+ const double gcr = gc_lat * std::numbers::pi / 180.0;
- return atan(tan(gcr)/cos2_ae) * 180.0/M_PI;
+ return atan(tan(gcr)/cos2_ae) * 180.0 * std::numbers::inv_pi;
}
/* Takes a projected "north" value, returns latitude in degrees. */
{
const double norm_x = x/i1924_equ_axis;
- return atan(sinh(norm_x)) * 180.0/M_PI;
+ return atan(sinh(norm_x)) * 180.0 * std::numbers::inv_pi;
}
/* Takes latitude in degrees, returns projected "north" value. */
double
HumminbirdBase::inverse_gudermannian_i1924(const double x)
{
- const double x_r = x/180.0 * M_PI;
- const double guder = log(tan(M_PI/4.0 + x_r/2.0));
+ const double x_r = x/180.0 * std::numbers::pi;
+ const double guder = log(tan(std::numbers::pi/4.0 + x_r/2.0));
return guder * i1924_equ_axis;
}
#include <cstdint> // for int32_t
#include <ctime> // for time_t
+#include <numbers> // for pi
#include <QString> // for QString
-constexpr double GPS_PI = 3.14159265358979323846;
+constexpr double GPS_PI = std::numbers::pi;
double GPS_Math_Deg_To_Rad(double v);
#include "lowranceusr.h"
#include <cinttypes> // for PRId64
-#include <cmath> // for M_PI, round, atan, exp, log, tan
+#include <cmath> // for round, atan, exp, log, tan
#include <cstdio> // for printf, sprintf, SEEK_CUR
#include <cstdint> // for int64_t
#include <cstdlib> // for abs
#include <cstring> // for strcmp, strlen
+#include <numbers> // for pi
#include <utility> // for as_const
#include <QByteArray> // for QByteArray
double
LowranceusrFormat::lat_mm_to_deg(double x)
{
- return (2.0 * atan(exp(x / SEMIMINOR)) - M_PI / 2.0) / DEGREESTORADIANS;
+ return (2.0 * atan(exp(x / SEMIMINOR)) - std::numbers::pi / 2.0) / DEGREESTORADIANS;
}
long
long
LowranceusrFormat::lat_deg_to_mm(double x)
{
- return round(SEMIMINOR * log(tan((x * DEGREESTORADIANS + M_PI / 2.0) / 2.0)));
+ return round(SEMIMINOR * log(tan((x * DEGREESTORADIANS + std::numbers::pi / 2.0) / 2.0)));
}
void
#ifndef LOWRANCEUSR_H_INCLUDED_
#define LOWRANCEUSR_H_INCLUDED_
-#include <cmath> // for M_PI, round, atan, exp, log, tan
+#include <cmath> // for round, atan, exp, log, tan
#include <cstdint> // for int64_t
+#include <numbers> // for pi
#include <QList> // for QList
#include <QString> // for QString
static constexpr int MAXUSRSTRINGSIZE = 256;
static constexpr double SEMIMINOR = 6356752.3142;
- static constexpr double DEGREESTORADIANS = M_PI/180.0;
+ static constexpr double DEGREESTORADIANS = std::numbers::pi/180.0;
static constexpr int MAX_TRAIL_POINTS = 9999;
static constexpr double UNKNOWN_USR_ALTITUDE = METERS_TO_FEET(-10000); /* -10000ft is how the unit stores unknown */
static constexpr int64_t base_time_secs = 946706400; /* Jan 1, 2000 00:00:00 */
#error This version of Qt is not supported.
#endif
-#if defined(_MSC_VER) && (_MSC_VER < 1920) /* MSVC 2017 or earlier */
-#error MSVC 2017 and earlier are not supported. Please use MSVC 2019 or MSVC 2022.
+#if defined(_MSC_VER) && (_MSC_VER < 1920) /* Visual Studio 2017 or earlier */
+#error Visual Studio 2017 and earlier are not supported. Please use Visual Studio 2019 or 2022.
#endif
if constexpr (DEBUG_LOCALE) {
#if defined __cplusplus
#include <algorithm> // for sort, stable_sort
-#include <cmath> // for M_PI
#include <cstdarg> // for va_list
#include <cstddef> // for NULL, nullptr_t, size_t
#include <cstdint> // for int32_t, uint32_t
#include <cstdio> // for NULL, fprintf, FILE, stdout
#include <ctime> // for time_t
+#include <numbers> // for inv_pi, pi
#include <optional> // for optional
#include <utility> // for move
*/
#include <cctype> // for isprint
-#include <cmath> // for cos, sin, atan2, pow, sqrt, M_PI
+#include <cmath> // for cos, sin, atan2, pow, sqrt
#include <cstdarg> // for va_end, va_list, va_start
#include <cstdio> // for sscanf, snprintf, vprintf, SEEK_SET
#include <cstdlib> // for free
#include <cstring> // for memset
+#include <numbers> // for inv_pi, pi
#include <QByteArray> // for QByteArray
#include <QChar> // for QChar
/* height above ellipsoid (in meters): */
*alt = AP/cos(*lat) - CA/sqrt(1 - CE2 * pow(sin(*lat), 2));
- *lat = *lat /M_PI*180;
- *lon = *lon /M_PI*180;
+ *lat = *lat * std::numbers::inv_pi * 180;
+ *lon = *lon * std::numbers::inv_pi * 180;
}
void
long double a = 6378137.0;
long double esqr = 6.69437999014e-3;
- long double llat = lat*M_PI/180;
- long double llng = lng*M_PI/180;
+ long double llat = lat * std::numbers::pi / 180;
+ long double llng = lng * std::numbers::pi / 180;
long double lalt = alt;
long double s = sin(llat);
// https://en.wikipedia.org/wiki/N-vector
// http://www.navlab.net/Publications/A_Nonsingular_Horizontal_Position_Representation.pdf
-#include <cfloat>
-#include <cmath>
-#include <cstdio>
-#include <iostream>
-#include <utility>
+#include "src/core/nvector.h"
-#include "nvector.h"
-#include "vector3d.h"
+#include <cfloat> // for DBL_EPSILON
+#include <cmath> // for sqrt, atan2, cos, nan, sin, cbrt
+#include <utility> // for pair
+
+#include "src/core/vector3d.h" // for Vector3D
namespace gpsbabel
{
{
Vector3D c_E = crossProduct(n_EA_E, n_EB_E).normalize();
double result = fabs((atan2(crossProduct(c_E, n_EX_E).norm(),
- dotProduct(c_E, n_EX_E)) - M_PI/2.0)) * MEAN_EARTH_RADIUS_METERS;
+ dotProduct(c_E, n_EX_E)) - std::numbers::pi/2.0)) * MEAN_EARTH_RADIUS_METERS;
return result;
}
#else
#ifndef NVECTOR_H
#define NVECTOR_H
-#include "defs.h"
-#include "vector3d.h"
+#include <numbers> // for pi
+#include <utility> // for pair
+
+#include "src/core/vector3d.h" // for Vector3D
namespace gpsbabel
{
constexpr double WGS84_SEMI_MINOR_AXIS_METERS = WGS84_SEMI_MAJOR_AXIS_METERS * WGS84_ASPECT_RATIO; // b
constexpr double WGS84_ECCENTRICITY_SQUARED = 1.0 - (WGS84_ASPECT_RATIO * WGS84_ASPECT_RATIO);
-constexpr double kRadiansPerDegree = M_PI/180.0;
+constexpr double kRadiansPerDegree = std::numbers::pi / 180.0;
constexpr double kDegreesPerRadian = 1.0/kRadiansPerDegree;
class PVector;